﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using LIMS.Shared;
using LIMS.Entities;
using System.Windows.Forms;

namespace LIMS.Windows
{

    public partial class UserManagement : LIMSPageBase<UserManagementPagePresenter>, IUserManagementPageView
    //public partial class UserManagement : Form
    {
        UserTypePermission m_oUserRights;
        private int iParentId = 0;
        private string sDepartmentId = string.Empty;
        public UserManagement()
        {
            InitializeComponent();
        }

        private void UserManagement_Load(object sender, EventArgs e)
        {

            try
            {
                oGridData = null;
                m_iUserId = 0;
                //this.Presenter.InitializeView();
                GetUsersBasedOnCriteria(string.Empty);
                DisplayGrid();
                EnableDisableControls(false);

                m_oUserRights = new UserTypePermission();
                m_oUserRights = SharedResource.GetUserRights(SharedResource.gLoggedinUser.UserType);

                SetUserRights();


                System.Windows.Forms.ToolTip ToolTipText = new System.Windows.Forms.ToolTip();
                ToolTipText.SetToolTip(this.btnNext, "Next");
                ToolTipText.SetToolTip(this.btnFirst, "First");
                ToolTipText.SetToolTip(this.btnPrevious, "Previous");
                ToolTipText.SetToolTip(this.btnLast, "Last");
                ToolTipText.SetToolTip(this.btnSpecific, "Go to specific");
                BindStatus();
                BindUserType();
                //BindDepartment();
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void SetUserRights()
        {
            try
            {
                if (m_oUserRights != null)
                {
                    btnDelete.Enabled = Convert.ToBoolean(m_oUserRights.DeleteRight);
                    btnEdit.Enabled = Convert.ToBoolean(m_oUserRights.EditRight);
                    btnAddNewUser.Enabled = Convert.ToBoolean(m_oUserRights.AddRight);
                    //if (!Convert.ToBoolean(m_oUserRights.EditRight))
                    //    grdUser.ReadOnly = !(Convert.ToBoolean(m_oUserRights.EditRight));
                }

            }
            catch (Exception ex)
            { }
        }

        private void BindUserType()
        {
            try
            {
                Dictionary<int, string> oUserType = Resource.UserTypeDic;
                int iUserType;
                iUserType = SharedResource.gLoggedinUser.UserType;
                switch (iUserType)
                {

                    case 1:
                        oUserType.Remove(1);
                        cmbUserType.DataSource = new BindingSource(oUserType,"");
                        break;
                    case 2:
                        oUserType.Remove(1);
                        oUserType.Remove(2);
                        cmbUserType.DataSource = new BindingSource(oUserType, "");
                        break;
                    case 3:
                        oUserType.Remove(1);
                        oUserType.Remove(2);
                        oUserType.Remove(3);
                        cmbUserType.DataSource = new BindingSource(oUserType, "");
                        break;
                    case 4:
                        oUserType.Remove(1);
                        oUserType.Remove(2);
                        oUserType.Remove(3);
                        //oUserType.Remove(4);
                        cmbUserType.DataSource = new BindingSource(oUserType, "");
                        break;
                    default:
                        cmbUserType.DataSource = new BindingSource(oUserType, "");
                        break;

                }
                //cmbUserType.DataSource = new BindingSource(Resource.UserTypeDic, "");
                cmbUserType.DisplayMember = "Value";
                cmbUserType.ValueMember = "Key";
                
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void BindStatus()
        {
            try
            {
                cmbStatus.DataSource = new BindingSource(Resource.UserStatusDic, "");
                cmbStatus.DisplayMember = "Value";
                cmbStatus.ValueMember = "key";

            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }
        //private void BindDepartment()
        //{

        //    lstDepartment.DataSource = SharedResource.GetHODDept(SharedResource.gLoggedinUser, true);
        //    lstDepartment.DisplayMember = "Name";
        //    lstDepartment.ValueMember = "Id";
        //}

        private void DisplayGrid()
        {
            try
            {
                if (grdUser.Columns[0].Displayed == false)
                {
                    DataGridViewCheckBoxColumn oChkColumn = new DataGridViewCheckBoxColumn(false);

                    oChkColumn.HeaderText = "Select";
                    oChkColumn.Name = "Select";
                    oChkColumn.Width = 50;

                    grdUser.Columns.Insert(0, oChkColumn);
                }

                grdUser.MultiSelect = false;
                grdUser.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                grdUser.AllowUserToAddRows = false;

                foreach (DataGridViewColumn dc in grdUser.Columns)
                {
                    if (dc.Index.Equals(0))
                    {
                        dc.ReadOnly = false;
                    }
                    else
                    {
                        dc.ReadOnly = true;
                    }
                }
                grdUser.RowHeadersVisible = false;
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        #region IUserManagementPageView Members

        private int iCurrentIndex;
        public int CurrentIndex
        {
            set
            {
                EnableDisableControls(true);
                iCurrentIndex = value;
                txtFirstName.Text = oUsers[iCurrentIndex].FirstName;
                txtLastName.Text = oUsers[iCurrentIndex].LastName;
                txtUserName.Text = oUsers[iCurrentIndex].UserName;
                txtEmail.Text = oUsers[iCurrentIndex].Email;
                txtEmployeeCode.Text = oUsers[iCurrentIndex].EmployeeCode;
                txtdateTime.Text = Convert.ToString(oUsers[iCurrentIndex].UserDOB);
                //txtPassword.Text = oUsers[iCurrentIndex].Password;
                //txtConfirmPassword.Text = oUsers[iCurrentIndex].Password;
                cmbUserType.SelectedValue = oUsers[iCurrentIndex].UserType;
                //lstDepartment.SelectedValue = 0;
                cmbStatus.SelectedValue = oUsers[iCurrentIndex].Status;
                //t_ddl_Status_MY.SelectedValue = Resource.GetCodedStatus(oUsers[CurrentIndex].Status, true);
                //if (oUsers[CurrentIndex].UserName != null)
                //{
                //    if (oUsers[CurrentIndex].UserName.Equals("admin"))
                //    {
                //        t_ddl_Status_MY.Enabled = false;
                //    }
                //}
                //t_ddl_PKGSPACEManager_MY.SelectedValue = Convert.ToString(oUsers[CurrentIndex].PackageManagerId);
                //t_ddl_Company_MY.SelectedValue = Convert.ToString(oUsers[CurrentIndex].CompanyId);
            }
            get
            {
                return iCurrentIndex;
            }
        }

        public void FillPageData()
        {
            throw new NotImplementedException();
        }

        private GridViewData oGridData;
        public GridViewData GridData
        {
            set
            {
                oGridData = value;
                lblTotal.Text = "/ " + (value.TotalRecords / value.PageSize + ((value.TotalRecords % value.PageSize > 0) ? 1 : 0)).ToString();
                txtPageNo.Text = value.PageIndex.ToString();
            }
            get
            {
                if (oGridData != null)
                {
                    return oGridData;
                }
                else
                {
                    GridViewData grdData = new GridViewData();
                    grdData.SortOrder = "ASC";
                    grdData.SortColumn = "CreatedDateTime";
                    grdData.PageSize = 10;//SetGridPageSize();
                    grdData.PageIndex = 1;
                    return grdData;
                }

            }
        }

        public void ShowMessage(MessageType type, string sMessage)
        {
            //throw new NotImplementedException();
        }

        private List<User> oUsers;
        public List<User> Users
        {
            get
            {
                if (oUsers == null)
                {
                    oUsers = new List<User>();
                }
                return oUsers;
            }
            set
            {
                oUsers = value;
                grdUser.DataSource = ConvertListToDataTable(oUsers);
                grdUser.Columns[0].Visible = false;
            }
        }

        #endregion

        private DataTable ConvertListToDataTable(List<User> list)
        {
            // New table.
            DataTable table = new DataTable();
            DataColumn oColumn0 = new DataColumn("Id", typeof(int));
            DataColumn oColumn1 = new DataColumn("First Name", typeof(string));
            DataColumn oColumn2 = new DataColumn("Last Name", typeof(string));
            DataColumn oColumn3 = new DataColumn("User Name", typeof(string));
            DataColumn oColumn4 = new DataColumn("Email", typeof(string));
            //DataColumn oColumn5 = new DataColumn("Email", typeof(string));
            table.Columns.Add(oColumn0);
            table.Columns.Add(oColumn1);
            table.Columns.Add(oColumn2);
            table.Columns.Add(oColumn3);
            table.Columns.Add(oColumn4);

            for (int i = 0; i < list.Count; i++)
            {
                DataRow oNewRow = table.NewRow();
                oNewRow["Id"] = list[i].Id;
                oNewRow["First Name"] = list[i].FirstName;
                oNewRow["Last Name"] = list[i].LastName;
                oNewRow["User Name"] = list[i].UserName;
                oNewRow["Email"] = list[i].Email;

                table.Rows.Add(oNewRow);
            }
            return table;
        }

        private void btnSaveUser_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtFirstName.Text.Trim()) || string.IsNullOrEmpty(txtLastName.Text.Trim()) ||
                    string.IsNullOrEmpty(txtEmail.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text.Trim()) ||
                    string.IsNullOrEmpty(txtConfirmPassword.Text.Trim()) || string.IsNullOrEmpty(txtUserName.Text.Trim()) ||
                    string.IsNullOrEmpty(txtEmployeeCode.Text.Trim()) || Convert.ToString(cmbStatus.SelectedValue) == "X" || Convert.ToInt16(cmbUserType.SelectedValue) == 0)
                {
                    MessageBox.Show("Fill mandatory(*) information.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                else if (!Validations.IsDate(txtdateTime.Text))
                {
                    MessageBox.Show("Date is not valid.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtdateTime.Focus();
                    return;
                }
                else if (txtConfirmPassword.Text != txtPassword.Text)
                {
                    MessageBox.Show("Passwords do not match.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    txtConfirmPassword.Text = string.Empty;
                    txtPassword.Text = string.Empty;
                    txtPassword.Focus();
                    return;
                }
                else
                {
                    oUsers[CurrentIndex].FirstName = txtFirstName.Text;
                    oUsers[CurrentIndex].LastName = txtLastName.Text;
                    oUsers[CurrentIndex].Email = txtEmail.Text;
                    oUsers[CurrentIndex].UserName = txtUserName.Text;
                    oUsers[CurrentIndex].Password = Resource.GenerateSHAPasswordHash(txtPassword.Text);
                    oUsers[CurrentIndex].CreatedBy = SharedResource.gLoggedinUser.UserType; 
                    oUsers[CurrentIndex].CreatedDateTime = DateTime.Now;
                    oUsers[CurrentIndex].Status = Convert.ToString(cmbStatus.SelectedValue);

                    oUsers[CurrentIndex].Designation = string.Empty;
                    oUsers[CurrentIndex].Description = string.Empty;
                    oUsers[CurrentIndex].DepartmentId = sDepartmentId;
                    oUsers[CurrentIndex].ParentId = iParentId;
                    oUsers[CurrentIndex].UserType = Convert.ToInt16(cmbUserType.SelectedValue);
                    oUsers[CurrentIndex].EmployeeCode = txtEmployeeCode.Text;
                    oUsers[CurrentIndex].UserDOB = Convert.ToDateTime(txtdateTime.Text);

                    if (this.Presenter.Save(oUsers[CurrentIndex]))
                    {
                        MessageBox.Show("User saved successfully.", "save user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        EnableDisableControls(false);
                        ClearData();
                    }

                    this.Presenter.InitializeView();
                    DisplayGrid();
                    SetUserRights();
                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void ClearData()
        {
            try
            {
                txtFirstName.Text = string.Empty;
                txtLastName.Text = string.Empty;
                txtEmail.Text = string.Empty;
                txtUserName.Text = string.Empty;
                txtPassword.Text = string.Empty;
                txtConfirmPassword.Text = string.Empty;
                cmbUserType.SelectedValue = 0;
                txtEmployeeCode.Text = string.Empty;
                cmbStatus.SelectedValue = "X";
                txtdateTime.Text = string.Empty;
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void grdUser_RowEnter(object sender, DataGridViewCellEventArgs e)
        {

        }

        //private void grdUser_CellClick(object sender, DataGridViewCellEventArgs e)
        //{
        //    bool bChkBoxSelected = false;
        //    int iUserId = Convert.ToInt32(grdUser.Rows[grdUser.CurrentRow.Index].Cells["Id"].Value);
        //    m_iUserId = iUserId;

        //    for (int iRowCount = 0; iRowCount < grdUser.Rows.Count; iRowCount++)
        //    {
        //        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)grdUser.Rows[iRowCount].Cells[0];
        //        if (cell is DataGridViewCheckBoxCell)
        //        {
        //            if ((bool)cell.EditedFormattedValue)
        //            {
        //                bChkBoxSelected = true;
        //                break;
        //            }
        //        }
        //    }

        //}

        private void grdUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //try
            //{
            //    bool bChkBoxSelected = false;
            int iUserId = Convert.ToInt32(grdUser.Rows[grdUser.CurrentRow.Index].Cells["Id"].Value);
            m_iUserId = iUserId;

            //    for (int iRowCount = 0; iRowCount < grdUser.Rows.Count; iRowCount++)
            //    {
            //        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)grdUser.Rows[iRowCount].Cells[0];
            //        if (cell is DataGridViewCheckBoxCell)
            //        {
            //            if ((bool)cell.EditedFormattedValue)
            //            {
            //                bChkBoxSelected = true;
            //                break;
            //            }
            //        }
            //    }
            //    if (bChkBoxSelected)
            //    {
            //        btnDelete.Enabled = true;
            //        btnEdit.Enabled = true;
            //    }
            //    else
            //    {
            //        btnDelete.Enabled = false;
            //        btnEdit.Enabled = false;
            //    }
            //}
            //catch (Exception ex)
            //{
            //    //Logger.Error("Error occured.", ex);
            //}

        }

        private static int m_iUserId = 0;

        private void btnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_iUserId > 0)
                {
                    int iSelectedRowsCount = 0;
                    int iRowIndex = 0;
                    for (int iRowCount = 0; iRowCount < grdUser.Rows.Count; iRowCount++)
                    {
                        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)grdUser.Rows[iRowCount].Cells[0];
                        if (cell is DataGridViewCheckBoxCell)
                        {
                            if ((bool)cell.EditedFormattedValue)
                            {
                                iRowIndex = iRowCount;
                                iSelectedRowsCount++;
                            }
                        }
                    }
                    if (iSelectedRowsCount > 1)
                    {
                        MessageBox.Show("Select single row to edit the record.", "Select user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }
                    else if (iSelectedRowsCount == 0)
                    {
                        MessageBox.Show("Select atleast one record to edit.", "Select user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    /// Edit
                    btnSaveUser.Enabled = true;
                    CurrentIndex = iRowIndex;
                }
                else
                {
                    MessageBox.Show("Select atleast one record to edit.", "Select user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_iUserId > 0)
                {
                    int iSelectedRowsCount = 0;
                    for (int iRowCount = 0; iRowCount < grdUser.Rows.Count; iRowCount++)
                    {
                        DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)grdUser.Rows[iRowCount].Cells[0];
                        if (cell is DataGridViewCheckBoxCell)
                        {
                            if ((bool)cell.EditedFormattedValue)
                            {
                                iSelectedRowsCount++;
                            }
                        }
                    }
                    if (iSelectedRowsCount == 0)
                    {
                        MessageBox.Show("Select atleast one record to delete.", "Delete user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return;
                    }

                    DialogResult oResult = MessageBox.Show("Are you sure to delete the selected records?", "Delete user", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (oResult.Equals(DialogResult.Yes))
                    {
                        /// Delete
                        for (int iRowCount = 0; iRowCount < grdUser.Rows.Count; iRowCount++)
                        {
                            DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)grdUser.Rows[iRowCount].Cells[0];
                            if (cell is DataGridViewCheckBoxCell)
                            {
                                if ((bool)cell.EditedFormattedValue)
                                {
                                    this.Presenter.Delete(oUsers[iRowCount]);
                                }
                            }
                        }
                        this.Presenter.InitializeView();
                        DisplayGrid();
                        SetUserRights();
                    }

                }
                else
                {
                    MessageBox.Show("Select atleast one record to delete.", "Delete user", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnFirst_Click(object sender, EventArgs e)
        {

            try
            {
                GridData.PageIndex = 1;//(GridData.TotalRecords / GridData.PageSize + ((GridData.TotalRecords % GridData.PageSize > 0) ? 1 : 0) -1 );
                GetUsersBasedOnCriteria(string.Empty);

            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void GetUsersBasedOnCriteria(string p_sCriteria)
        {
            try
            {
                if (txtSearch.Text.Trim().Length == 0)
                {
                    this.Presenter.InitializeView();
                }
                else
                {
                    this.Presenter.SearchUserByKeyword(p_sCriteria);
                }
                DisplayGrid();
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnPrevious_Click(object sender, EventArgs e)
        {
            try
            {
                if (GridData.PageIndex > 1)
                {
                    GridData.PageIndex--;
                    GetUsersBasedOnCriteria(string.Empty);

                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }

        }


        private void btnLast_Click(object sender, EventArgs e)
        {
            try
            {
                GridData.PageIndex = (GridData.TotalRecords / GridData.PageSize + ((GridData.TotalRecords % GridData.PageSize > 0) ? 1 : 0));
                GetUsersBasedOnCriteria(string.Empty);

            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnSpecific_Click(object sender, EventArgs e)
        {
            try
            {
                int userCurrentPage = 0;

                if (!int.TryParse(txtPageNo.Text, out userCurrentPage))
                {
                    userCurrentPage = 1;
                }

                int maxPageSize = (GridData.TotalRecords / GridData.PageSize + ((GridData.TotalRecords % GridData.PageSize > 0) ? 1 : 0));
                if (userCurrentPage > maxPageSize)
                {
                    userCurrentPage = 1;
                }
                GridData.PageIndex = userCurrentPage;
                GetUsersBasedOnCriteria(string.Empty);

            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                int maxPageSize = (GridData.TotalRecords / GridData.PageSize + ((GridData.TotalRecords % GridData.PageSize > 0) ? 1 : 0) - 1);

                if (GridData.PageIndex <= maxPageSize)
                {
                    GridData.PageIndex++;
                    GetUsersBasedOnCriteria(string.Empty);
                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnAddNewUser_Click(object sender, EventArgs e)
        {
            try
            {
                EnableDisableControls(true);
                txtFirstName.Focus();
                User newUser = new User();
                oUsers.Add(newUser);
                CurrentIndex = oUsers.Count - 1;
                
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                string sCriteria = txtSearch.Text.Trim();
                if (sCriteria.Length > 0)
                {
                    if (sCriteria.Contains("*"))
                    {
                        if (sCriteria.Equals("*"))
                        {
                            sCriteria = string.Empty;
                        }
                        else
                        {
                            sCriteria = sCriteria.Replace("*", "%");
                        }
                    }
                    else if (sCriteria.Contains("?"))
                    {
                        sCriteria = sCriteria.Replace("?", "%");
                    }
                }
                GetUsersBasedOnCriteria(sCriteria);
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        /// <summary>
        /// Enable disable form controls on action basis.
        /// if bValue is true contrlos will be enabled else disabled.
        /// </summary>
        /// <param name="bValue"></param>
        private void EnableDisableControls(bool bValue)
        {
            try
            {
                txtFirstName.Enabled = bValue;
                txtLastName.Enabled = bValue;
                txtEmail.Enabled = bValue;
                txtUserName.Enabled = bValue;
                txtPassword.Enabled = bValue;
                txtConfirmPassword.Enabled = bValue;
                cmbUserType.Enabled = bValue;
                txtEmployeeCode.Enabled = bValue;
                txtdateTime.Enabled = bValue;
                cmbStatus.Enabled = bValue;
                btnSaveUser.Enabled = bValue;

            }
            catch (Exception ex)
            { }
        }

        private void cmbUserType_SelectionChangeCommitted(object sender, EventArgs e)
        {
            try
            {
                int iUserType = 0;
                iUserType = Convert.ToInt32(cmbUserType.SelectedValue);
                switch (iUserType)
                {
                    case 1:
                        HODepartmentsPopup oHODForm = new HODepartmentsPopup(SharedResource.gLoggedinUser, 1);
                        oHODForm.ShowDialog();
                        if (oHODForm.DepartmentID.Length > 0)
                        {
                            sDepartmentId = oHODForm.DepartmentID;
                            iParentId = 1; //for HOD parent should always be Admin user
                        }
                        else
                        {
                            cmbUserType.SelectedValue = 0;
                        }
                        break;
                    case 2:

                        DepartmentPopUp oFormDept = new DepartmentPopUp(SharedResource.gLoggedinUser, 2);
                        oFormDept.ShowDialog();
                        if (oFormDept.DepartmentID.Length > 0)
                        {
                            sDepartmentId = oFormDept.DepartmentID;
                        }
                        else
                        {
                            cmbUserType.SelectedValue = 0;
                        }
                        break;

                    case 3:


                        ManagerPopUp oForm = new ManagerPopUp(SharedResource.gLoggedinUser);
                        oForm.ShowDialog();
                        if (oForm.ManagerId > 0 && oForm.DepartmentID.Length > 0)
                        {
                            iParentId = oForm.ManagerId;
                            sDepartmentId = oForm.DepartmentID;
                        }
                        else
                        {
                            cmbUserType.SelectedValue = 0;
                        }

                        break;


                    case 4:

                        ///show supervisor popup
                        SupervisorPopUp oFormSup = new SupervisorPopUp(SharedResource.gLoggedinUser);
                        oFormSup.ShowDialog();
                        if (oFormSup.SupervisorId > 0 && oFormSup.DepartmentID.Length > 0)
                        {
                            iParentId = oFormSup.SupervisorId;
                            sDepartmentId = oFormSup.DepartmentID;
                        }
                        else
                        {
                            cmbUserType.SelectedValue = 0;
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                //Logger.Error("Error occured.", ex);
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            ClearData();
        }

    }
}
